package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import cn.wolfcode.trip.base.service.ITravelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//游记资源的控制器
@RestController
@RequestMapping("/travels")
public class TravelController {
    @Autowired
    private ITravelService travelService;
    @Autowired
    private ITravelCommendService travelCommendService;

    /*
    根据游记的id查询游记
    资源:/travels/{id}
    动作:GET
    参数:
     */
    @GetMapping("/{id}")
    public Object getTravelById(@PathVariable Long id) {
        return travelService.get(id);
    }

    /*
    获取所有公开发布的游记
    资源:/travels
    动作:GET
    参数:isPublic=true&state=2
     */
    @GetMapping
    public Object queryTravels(TravelQueryObject qo) {
        qo.setOrderBy("t.releaseTime desc");
        return travelService.queryTravel(qo);
    }

    /*
    获取当前周/月/攻略的推荐
    资源:/travels/commends
    动作:GET
    参数:type=x
     */
    @GetMapping("/commends")
    public Object listCommend(@RequestParam Integer type) {
        return travelCommendService.listCommend(type);
    }

}
